#include "entt/entt.hpp"
#include "entt/meta/meta.hpp"
#include "entt/meta/factory.hpp"
#include "../scion_utilities/hzpch.h"

using namespace entt::literals;

struct TestType
{
  int x{1}, y{2}, z{3};
  void testing(int a, int b)
  {
    std::cout << "X=" << x << ", Y=" << y << ", Z=" << z << ", a=" << a << ", b=" << b << std::endl;
  }
};

void TestingFree(int a, int b)
{
  std::cout << "Free Function called with a=" << a << ", b=" << b << std::endl;
}
int main()
{
  std::cout << "Testing1..." << std::endl;
  // 创建测试类型的元数据
  entt::meta_factory<TestType>{}
      .type(entt::type_hash<TestType>())
      .data<&TestType::x>("x"_hs)
      .data<&TestType::y>("y"_hs)
      .data<&TestType::z>("z"_hs)
      .func<&TestType::testing>("testing"_hs);
  // 从元数据创建实例
  auto type = entt::resolve<TestType>();
  auto data_x = type.data("x"_hs);

  auto any = type.construct();
  auto x_value = data_x.set(any, 5);

  auto func = entt::resolve<TestType>().func("testing"_hs);
  func.invoke(any, 12, 12);

  for (auto &&[id, type] : entt::resolve())
  {
    std::cout << "Registered type: " << type.info().name() << std::endl;
  }
  std::cout << "Testing2..." << std::endl;
  entt::meta_factory<TestType>().type(entt::type_hash<TestType>::value()).data<&TestType::x>("x"_hs).data<&TestType::y>("y"_hs).data<&TestType::z>("z"_hs).func<&TestType::testing>("testing2"_hs);

  auto freeFunc = entt::resolve<TestType>().func("testing2"_hs);
  freeFunc.invoke({}, 20, 30);

  return 0;
}